// redux基本简单实现
function createStore(reducer,initialState){
  let state = initialState;
  let listeners = [];
  function getState(){
    return state;
  }
  function dispatch(action){
    state = reducer(state, action);
    listeners.forEach(l=>l());
  }
  function subscribe(listener){
    listeners.push(listener);
  }
  return {getState, dispatch,subscribe}
}
function reducer(state,action){
   return action.color;
}

let store = createStore(reducer,'绿色');
store.subscribe(()=>{
console.log(store.getState());
})
store.dispatch({type:'changeColor',color: '红色'})
store.dispatch({type:'changeColor',color: 'lan色'})


//实现一个函数，判断一组数字是否连续。当出现连续数字的时候以‘-’输出。
// 如： const arr = [ 2, 3, 4, 7, 8, 9, 10,13,15]
// 期望结果：["2-4", "7-10", 13, 15]
